home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 August / SGI IRIX 6.5 Applications 1999 August.iso / dist / netwr_client.idb / var / spool / lp / model / nwpsinterface.z / nwpsinterface
Text File  |  1998-05-06  |  4KB  |  206 lines

  1. #!/bin/sh 
  2. #
  3. # lp interface for generic PostScript printers, NetWare client interface
  4. #
  5. # $Revision: 1.1 $
  6. # $Date: 1997/01/22 02:16:38 $
  7. #
  8. # Info for administration tools:
  9. #
  10. #
  11.  
  12. NAME=
  13. PRINTER=
  14. ZONE=
  15. USER=
  16. PASSWD=
  17. TYPE=PostScript
  18.  
  19. exec 2>> log
  20. #logfile=/var/spool/lp/log               # lp spooler error log file
  21. #exec 2>> $LOGFILE
  22.  
  23. # Change the following to set up defaults
  24. GTMPDIR=/var/tmp
  25. #BANNER=1
  26. BANNER=0
  27. # Whether pages come out of the printer face up or face down.
  28. FACEUP=0
  29.  
  30. # If pages come out face down, don't reverse page order for input text.
  31. if [ $FACEUP = 0 ]
  32. then
  33.     opts="$opts -U"
  34. fi
  35.  
  36. LOGFILE=log
  37. RAW=0
  38. send=/usr/lib/print/lptops
  39. #VERBOSE=1
  40. VERBOSE=0
  41.  
  42. #
  43. # Grab command line arguments
  44. printer=`basename $0`
  45. seqid=$1
  46. name=$2
  47. title="$3"
  48. copies=$4
  49. options="$5"
  50. shift; shift; shift; shift; shift
  51. files="$*"
  52.  
  53. if [ $PASSWD = "_" ]
  54. then 
  55.     nwlogin="/usr/etc/netware/nwlogin $ZONE $USER"
  56. else
  57.     nwlogin="/usr/etc/netware/nwlogin $ZONE $USER $PASSWD"
  58. fi
  59.  
  60. psf="/usr/etc/netware/nprint -queue $PRINTER -server $ZONE"
  61. nwlogout="/usr/etc/netware/nwlogout $ZONE"
  62.  
  63. if [ -z "$title" ] ; then
  64.         title=`basename $1`
  65. fi
  66.  
  67. if [ ! -w "$LOGFILE" ] ; then
  68.         disable -r"can't access log file $LOGFILE" $printer 1>/dev/console 2>&1
  69.         exit 1
  70. fi
  71.  
  72.  
  73. for j in $options
  74. do      case $j in
  75.         -verbose | verbose | -debug | debug)  VERBOSE=1;;
  76.     -noverbose | noverbose) VERBOSE=0;;
  77.     -banner | banner) BANNER=1;;
  78.     -nobanner | nobanner | -h | h) BANNER=0;;
  79.     -raw | raw)      RAW=1;;
  80.     -cooked | cooked) RAW=0;;
  81.         *)      opts="$opts $j";;
  82.         esac
  83. done
  84.  
  85. if [ $VERBOSE != 0 ]
  86. then
  87.         echo $printer: $seqid $name "$title" Start - `date` >> $LOGFILE
  88. fi
  89.  
  90. SetTrap()
  91. #
  92. # This routine sets up the proper trap command.
  93. # When a job is cancelled, the spooler sends us a SIGTERM.
  94. # We could also get a SIGHUP or a SIGINT, so we'll catch those.
  95. #
  96. # It removes temporary/intermediate files created while filtering.
  97. {
  98.         trap '/bin/rm -f $GTMPDIR/b$seqid # CleanTempFiles
  99.               exit' 1 2 15      # catch SIGHUP, SIGINT, and SIGTERM
  100. }
  101.  
  102. SetTrap            # Set the cancellation trap
  103.  
  104.  
  105. # Change this for prettier banners or different number of columns
  106. x="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
  107. y="<=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=><=>"
  108.  
  109. if [ $BANNER != 0 ]
  110. then
  111.     touch $GTMPDIR/b$seqid
  112.     echo "$x\n$x\n$x\n$x\n" >> $GTMPDIR/b$seqid
  113.     /usr/bin/banner "$name" >>  $GTMPDIR/b$seqid
  114.     echo "\n" >>  $GTMPDIR/b$seqid
  115.     user=`grep "^$name:" /etc/passwd | line | cut -d: -f5`
  116.     if [ "$user" = "" ]
  117.     then
  118.         user=`(ypmatch $name passwd | line | cut -d: -f5) 2> /dev/null`
  119.     fi
  120.     if [ -n "$user" ]
  121.     then
  122.         echo "User: $user\n" >>  $GTMPDIR/b$seqid
  123.     else
  124.         echo "\n" >>  $GTMPDIR/b$seqid
  125.     fi
  126.     echo "Request id: $seqid    Printer: `basename $0`\n" >>  $GTMPDIR/b$seqid 
  127.     date >> $GTMPDIR/b$seqid
  128.     echo "\n" >>  $GTMPDIR/b$seqid
  129.     if [ -n "$title" ]
  130.     then
  131.         /usr/bin/banner $title >> $GTMPDIR/b$seqid
  132.     fi
  133. #    echo "\014\c" >> $GTMPDIR/b$seqid
  134. #Trailer on the banner page
  135.     echo "$x\n$x\n$x\n$x\n" >> $GTMPDIR/b$seqid
  136. fi
  137.  
  138. if [ $BANNER != 0 -a $FACEUP != 1 ]
  139. then
  140.     $send $GTMPDIR/b$seqid | $psf 2> /dev/null
  141.     echo "print banner" >> $LOGFILE
  142. fi
  143.  
  144. i=1
  145. while [ $i -le $copies ]
  146. do
  147.  
  148.     for file in $files
  149.     do
  150.         realfile="`/sbin/ls -l $file | /usr/bin/awk '{ print $11 }'`"
  151.         magic=`dd bs=1 count=2 if=$file 2> /dev/null`
  152.         if [ "$magic" = "%!" ]
  153.         then
  154.             $nwlogin
  155.             $psf $realfile
  156.             $nwlogout
  157.  
  158.         else
  159.             isend=/usr/lib/print/pprint
  160.             # check to see if it is an image file
  161.             set -- `dd bs=1 count=2 < $file 2> /dev/null | od -h`
  162.             if [ "$2" = 01da -a -x $isend ]
  163.             then
  164.                 $nwlogin
  165.                 $isend $realfile | $psf
  166.                 $nwlogout
  167.  
  168.             else
  169.                 magic=
  170.                 magic="`/bin/file $file | /usr/bin/cut -d: -f2`"
  171.                 case "$magic" in 
  172.                     *script* | *ascii* | *command* | *English* | *ext* | *iso8859* )  
  173.                      $nwlogin
  174.                      $psf $realfile
  175.                      $nwlogout;;
  176.                         
  177.                     * )
  178.                         temp="$printer: Unknown type of file(bad magic)  $file skipped..."
  179.                         echo $temp >> $LOGFILE
  180.                             echo $temp >&2
  181.                         exit 1 ;;
  182.                     esac    
  183.             fi
  184.         fi
  185.     done
  186.     i=`expr $i + 1`
  187. done
  188.  
  189. if [ $BANNER != 0 -a $FACEUP != 0 ]
  190. then
  191.           $send $GTMPDIR/b$seqid 2> /dev/null
  192. fi
  193.  
  194. if [ $VERBOSE != 0 ]
  195. then
  196.         echo $printer: $seqid End - `date` >> $LOGFILE
  197. fi
  198.  
  199. if [ $BANNER != 0 ]
  200. then
  201.     /bin/rm -f $GTMPDIR/b$seqid
  202. fi
  203.  
  204. exit 0
  205.  
  206.